package com.uchiha.nova.mainService.controller;


import com.uchiha.nova.core.model.LogUsual;
import com.uchiha.nova.core.model.LogApi;
import com.uchiha.nova.core.model.LogError;
import com.uchiha.nova.core.tool.api.R;
import com.uchiha.nova.mainService.service.ILogApiService;
import com.uchiha.nova.mainService.service.ILogErrorService;
import com.uchiha.nova.mainService.service.ILogUsualService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author 周林静
 * @Date 2021-10-27 13:16
 * @Version 1.0
 */
@RestController
@Slf4j
@RequestMapping("/log")
public class LogSaveController {
    @Resource
    ILogApiService logApiService;
    @Resource
    ILogUsualService logUsualService;
    @Resource
    ILogErrorService logErrorService;

    /**
     * 保存错误日志
     *
     * @param logUsual
     * @return
     */
    @PostMapping("/saveUsualLog")
    public R<Boolean> saveUsualLog(@RequestBody LogUsual logUsual){
        log.info("saveUsualLog:{}",logUsual);

        return R.status(logUsualService.save(logUsual));
    }

    /**
     * 保存操作日志
     *
     * @param logApi
     * @return
     */
    @PostMapping("/saveApiLog")
    R<Boolean> saveApiLog(@RequestBody LogApi logApi){
        log.info("saveApiLog:{}",logApi);
        logApiService.save(logApi);
        return R.success("保存成功");
    };

    /**
     * 保存错误日志
     *
     * @param logError
     * @return
     */
    @PostMapping("/saveErrorLog")
    R<Boolean> saveErrorLog(@RequestBody LogError logError){
        log.info("saveErrorLog:{}",logError);
        return R.status(logErrorService.save(logError));
    };
}
